<%--
功能: 单个上传组件
--%>
<%@ tag body-content="empty"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ attribute name="fileInputId" required="true" type="java.lang.String" description="上传field ID"%>
<%@ attribute name="uploadCategory" required="false" type="java.lang.String" description="输入上传的目录名,如category,product等,对应前台media下的目录,默认是others目录"%>
<%@ attribute name="uploadFileTypes" required="false" type="java.lang.String" description="上传文件格式，例如jpg,gif"%>
<%@ attribute name="cssClass" required="false" type="java.lang.String" description="按钮样式"%>
<%@ attribute name="onComplete" required="false" type="java.lang.String" description="当上传完毕后，调用的回调函数"%>
<%@ attribute name="onSelect" required="false" type="java.lang.String" description="浏览文件后，调用的回调函数"%>
<c:set var="plugin_upload" value="true" scope="request"/>
<c:if test="${empty uploadCategory}">
	<c:set var="uploadCategory" value="others" scope="page"/>
</c:if>
<c:if test="${empty cssClass}">
	<c:set var="cssClass" value="upload_img_1" scope="page"/>
</c:if>

<script type="text/javascript" >
$j(document).ready(function(){
	var urlAction='/dialog/upload.html?uploadCategory=${uploadCategory}&fileInputId=${fileInputId}';
	<c:if test="${not empty onComplete}">
		urlAction+="&onCompleteHandler=${onComplete}";
	</c:if>
	var plugin_upload_valid=true;
	$j('<input type="button" class="${cssClass}"/>').insertAfter("#${fileInputId}").upload({
	   	name: 'file',
       	action:  __ctxPath+urlAction,
       	enctype: 'multipart/form-data',
       	params: {},
       	onSubmit: function() {return plugin_upload_valid;},
       	onComplete: function() {},
       	onSelect: function() {
       		var supportedSuffixs="${uploadFileTypes}";
       		plugin_upload_valid = true;
			var idx = this.filename().lastIndexOf(".");
			if (idx == -1 || idx >= this.filename().length) {
				plugin_upload_valid = false;
			}
			var suffix = this.filename().substring(idx + 1, this.filename().length).toLowerCase();
			if (plugin_upload_valid && (supportedSuffixs!="")) {
				plugin_upload_valid = (supportedSuffixs.toString().indexOf(suffix) >= 0);
			}
			if (!plugin_upload_valid) {
				jAlert(__FMT.error_upload_unsupport + ":" + supportedSuffixs.toString());
				return false;
			}
			<c:if test="${not empty onSelect}">
				plugin_upload_valid=${onSelect}.call(this,this.filename());
			</c:if>
       	},
       	autoSubmit: true
	});
	$j("#${fileInputId}").wrap("<div style='float:left;'></div>"); 
});
</script>